package com.platform.user.api;

import com.platform.common.constant.RedisConstants;
import com.platform.common.entity.PageResult;
import com.platform.user.dto.UserDTO;
import com.platform.user.vo.UserVO;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author GH
 **/

@RequestMapping("/internal/user")
public interface UserApi {
    String SERVICE_NAME = "user-service";

    /**
     * 根据username查询userid
     *
     * @param username
     */
    @GetMapping("/usernameToId")
    @Cacheable(key = "#username", value = RedisConstants.USERNAME_TO_USERID)
    String accountToId(@RequestParam("username") String username);

    /**
     * 根据userId查询username
     *
     * @param id
     */
    @GetMapping("/idToUsername")
    @Cacheable(key = "#id", value = RedisConstants.USER_ID_TO_USERNAME)
    String idToAccount(@RequestParam("id") String id);

    /**
     * 根据userId查询nickname
     *
     * @param id
     */
    @GetMapping("/idToNickname")
    @Cacheable(key = "#id", value = RedisConstants.USER_ID_TO_NICKNAME)
    String idToNickname(@RequestParam("id") String id);

    /**
     * @Description 查询具体用户权限
     **/
    @GetMapping("/idToRoles")
    @Cacheable(key = "#id", value = RedisConstants.USER_ID_TO_ROLES)
    List<String> queryRolesById(@RequestParam("id") String id);

    @PostMapping("/ban")
    Boolean ban(@RequestParam("id") String id);

    @GetMapping("/page")
    PageResult<UserVO> pageUsers(@RequestParam("page") Integer page,
                                 @RequestParam("size") Integer size);

    @PostMapping("/resetPwd")
    Boolean updateById(@RequestBody UserDTO userDTO);

    @DeleteMapping("/delete")
    Boolean removeById(@RequestParam("id") String id);
}